package network;

import java.io.Serializable;


public class Buddy implements Comparable<Buddy>, Serializable, Cloneable{

	/**
	 * 
	 */
	
	private static final long serialVersionUID = -6232503269940457465L;
	private String name;
	private Status status;

	public Buddy(String name, Status status) {
		this.name = name;
		this.status = status;
	}

	@Override
	public int compareTo(Buddy o) {
		return this.name.compareTo(o.name);
	}
	
	public Object clone(){
		String n = new String(name);
		return new Buddy(n, status);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null || !(obj instanceof Buddy))
			return false;
		
		Buddy other = (Buddy) obj;
		if (this.name == other.name)
			return true;
		if(this.name == null || other.name == null)
			return false;
		else
			return name.equals(other.name);
	}
	
	public String getName() {
		return name;
	}

	public Status getStatus() {
		return status;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	public boolean isOnline() {
		return (this.status == Status.ONLINE);
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public String toString() {
		return name + "@" + status;
	}
	
}
